package com.tuozixuan.camel;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class FilterDemoRoute extends RouteBuilder {

	@Override
	public void configure() {
	    
	    
	    //from("file:inboxDir").filter(simple("${body} contains 'foo'")).to("direct:saveFile");
	    
	    // 通过自定义方式过滤
	    from("timer:hello?period={{timer.period}}").routeId("filterDemo")
        .transform().method("myBean", "saySomething")
        .filter().method("customFilterBean", "startsWithHello")
            .to("log:foo")
        .end()
        .to("stream:out");
	    
	    // 通过Simple表达式过滤
//	    from("timer:hello?period={{timer.period}}").routeId("filterDemo")
//        .transform().method("myBean", "saySomething")
//        .filter(simple("${body} contains 'foo'"))
//            .to("log:foo")
//        .end()
//        .to("stream:out");
	    
	    // 通过谓词表达式过滤
//	       from("timer:hello?period={{timer.period}}").routeId("filterDemo")
//	        .transform().method("myBean", "saySomething")
//	        .filter(exchange -> exchange.getMessage().getBody(String.class).startsWith("Hello"))
//	            .to("log:foo")
//	        .end()
//	        .to("stream:out");
	    
	}

}
